package com.clkj.tramcarlibrary.fragment.stopDetail;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.clkj.tramcarlibrary.R;
import com.clkj.tramcarlibrary.entity.StopDetail;

public class StopDetailFragment extends DialogFragment {

    private TextView tv_station;
    private TextView tv_nm_firstTramcar;
    private TextView tv_nm_secondTramcar;
    private TextView tv_tyg_firstTramcar;
    private TextView tv_tyg_secondTramcar;
    private TextView tv_nm_time, tv_tyg_time;


    private StopDetail stopDetail;
    private StopDetailContract.Presenter presenter;

    public StopDetailFragment() {
        // Required empty public constructor
    }

    public static StopDetailFragment newInstance(StopDetail stopDetail) {
        //创建一个带有参数的Fragment实例
        StopDetailFragment fragment = new StopDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("stopDetail", stopDetail);
        fragment.setArguments(bundle);//把参数传递给该DialogFragment
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        //presenter = new StopDetailPresenter(this, SchedulerProvider.getInstance(), HttpService.Factory.create(Constants.BASE_URL_FOR_TAXI_ABOUT_INFO));
        View view = inflater.inflate(R.layout.fragment_stop_detail, container, false);
        tv_station = (TextView) view.findViewById(R.id.tv_station);
        tv_nm_firstTramcar = (TextView) view.findViewById(R.id.tv_nm_firstTramcar);
        tv_nm_secondTramcar = (TextView) view.findViewById(R.id.tv_nm_secondTramcar);
        tv_tyg_firstTramcar = (TextView) view.findViewById(R.id.tv_tyg_firstTramcar);
        tv_tyg_secondTramcar = (TextView) view.findViewById(R.id.tv_tyg_secondTramcar);
        tv_nm_time= (TextView) view.findViewById(R.id.tv_nm_time);
        tv_tyg_time= (TextView) view.findViewById(R.id.tv_tyg_time);

        stopDetail = (StopDetail) getArguments().getSerializable("stopDetail");
        tv_station.setText(stopDetail.getNmdir().getStationName());

        tv_nm_firstTramcar.setText(stopDetail.getNmdir().getFirstChe() + "  " + stopDetail.getNmdir().getFirstDistance());
        tv_nm_secondTramcar.setText(stopDetail.getNmdir().getSecondChe() + "  " + stopDetail.getNmdir().getSecondDistance());
        tv_tyg_firstTramcar.setText(stopDetail.getTygdir().getFirstChe() + "  " + stopDetail.getTygdir().getFirstDistance());
        tv_tyg_secondTramcar.setText(stopDetail.getTygdir().getSecondChe() + "  " + stopDetail.getTygdir().getSecondDistance());
        tv_nm_time.setText("首班"+stopDetail.getFstime().get(0).getFirst_time()+"  末班"+stopDetail.getFstime().get(0).getLast_time());
        tv_tyg_time.setText("首班"+stopDetail.getFstime().get(0).getFirst_time_other()+"  末班"+stopDetail.getFstime().get(0).getLast_time_other());
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
       // getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

        /*
        //设置DialogFragment样式一
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height);
        getDialog().getWindow().setGravity(Gravity.BOTTOM);*/
        //设置DialogFragment样式二
        Window win = getDialog().getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);
        win.setGravity(Gravity.CENTER);
        win.setBackgroundDrawableResource(R.color.transparent);
    }

    //展示数据
 /*   @Override
    public void showStopDetail(StopDetail stopDetail) {
        tv_nm_firstTramcar.setText(stopDetail.getNmdir().getFirstChe() + "  " + stopDetail.getNmdir().getFirstDistance());
        tv_nm_secondTramcar.setText(stopDetail.getNmdir().getSecondChe() + "  " + stopDetail.getNmdir().getSecondDistance());
        tv_tyg_firstTramcar.setText(stopDetail.getTygdir().getFirstChe() + "  " + stopDetail.getTygdir().getFirstDistance());
        tv_tyg_secondTramcar.setText(stopDetail.getTygdir().getSecondChe() + "  " + stopDetail.getTygdir().getSecondDistance());
    }*/

   /* @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void showError() {
        Toast.makeText(getActivity(), "获取失败，请重试", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void setPresenter(StopDetailContract.Presenter presenter) {
        this.presenter = presenter;
    }*/

}
